package com.youcheng.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.function.Predicate;

@EnableOpenApi
@Configuration
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("分组二");

        //
    }


    @Bean
    public Docket docket(Environment environment){
        //判断当前的环境 如果是dev环境就开启swagger
        //Profiles profiles = Profiles.of("dev");
        //boolean flag = environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                //.enable(false)  //关闭swagger 则不能在浏览器访问

                .groupName("分组一")
                //指定扫描哪些包下的接口
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.youcheng.controller"))
                //.paths(PathSelectors.ant())  精确指定要扫描哪些
                .build();
                //
    }

    /**
     * API 页面上半部分展示信息
     */
    private ApiInfo apiInfo() {

        return new ApiInfoBuilder().title("cc_cms Api Doc")
                .description("努力、奋斗")
                .contact(new Contact("chanchow", "http://www.qilin668.com", "624665630@qq.com"))
                .version("1.0.0")
                .build();
    }

}
